#!/usr/bin/env python
# -*- coding: utf-8 -*-

import rospy
from turtlesim.srv import TeleportRelative
import math
import sys

def turtle_teleport_relative():
    # ROS节点初始化
    rospy.init_node('turtle_square_using_service')

    # 发现/turtle1/teleport_relative服务后，创建一个服务客户端，连接名为/turtle1/teleport_relative的service
    rospy.wait_for_service( '/turtle1/teleport_relative')
    try:
        move_turtle = rospy.ServiceProxy( '/turtle1/teleport_relative', TeleportRelative)

	# 请求服务调用，输入请求数据
        response = move_turtle(3.0, 0.0)
        response = move_turtle(3.0, math.pi/2.0)
        response = move_turtle(3.0, math.pi/2.0)
        response = move_turtle(3.0, math.pi/2.0)
        return response
    except (rospy.ServiceException, rospy.ROSException, e):
        print("Service call failed: %s" % e)
        return False

if __name__ == "__main__":
    # 服务调用并显示调用结果
    turtle_teleport_relative()
    print("Turtle draws a square successfully!")
